package appapi.controller.oider;

import appapi.common.ResponseBean;
import appapi.entity.mqtt.Appuser;
import appapi.entity.mqtt.Areapath;
import appapi.service.AppuserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version: java version 1.8
 * @Author: Ygp Work
 * @description:
 * @date: 2023-07-07 11:06
 */
@Api(tags = "app調試用戶接口")
@RestController
@RequestMapping("/api/appuser")
@CrossOrigin
public class AppuserController {
    @Autowired
    AppuserService appuserService;
    @GetMapping
    @ApiOperation(value = "查询所有的用户")
    @CrossOrigin
    public ResponseBean<List<Appuser>> getAllDevices() {
        List<Appuser> devicesList = appuserService.getAll();
        int size = devicesList.size();
        if (!devicesList.isEmpty()) {
            return ResponseBean.success(size,devicesList);
        } else {
            return ResponseBean.fail("查询失败，设备列表为空");
        }
    }

    @PostMapping
    @ApiOperation(value = "更新用户")
    @CrossOrigin
    public ResponseBean insertDevices(@RequestBody Appuser appuser) {
        appuserService.insertAppuser(appuser);
        return ResponseBean.success();
    }
}
